<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- 引入easyui的样式 -->
<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/themes/default/easyui.css">
<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/themes/icon.css">
<!-- js文件 -->
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
</head>
<script type="text/javascript">
//页面加载时发送请求
$(function(){
	$('#psg').datagrid({
		url:"findPersonage",
		queryParams: {			
			uid:"${user.uid}",
		}
	});
});
function formatOper(val,row,index){  
	return '<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="updPer('+index+')">修改信息</a>&nbsp'+
	 '&nbsp<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="updPsw('+index+')">重置密码</a>';     
 } 
//修改个人信息
function updPer(index) {
    $('#psg').datagrid('selectRow',index);
    var row = $('#psg').datagrid('getSelected');
    if (row){  
	//获取被选中需要修改的信息	
	 $('#dlg').dialog('open').dialog('center').dialog('setTitle','用户信息修改');
	 $('#fm').form('clear');
	 $('#sd').hide(); $('#ok').show();$('#refer').hide();
	 $('#un').hide(); $('#up').hide();
	 $('#na').show(); $('#ag').show(); 
	 $('#ad').show(); $('#nm').show();
	 $('#np').hide(); $('#nup').hide();
	 //将获取的需要修改的信息放在修改框里面
	 	var user =$("#psg").datagrid('getSelected');
		$("#uid").textbox('setValue',user.uid);
		$("#name").textbox('setValue',user.name);
		$("#age").textbox('setValue',user.age);
		$("#address").textbox('setValue',user.address);
		$("#number").textbox('setValue',user.number);	

	//将修改的信息请求发送至后台处理 	
	 $(function(){
		 $("#ok").click(function(){
			 user.uid = $("#uid").val();
			 var userobj=new Object();
			 userobj.name = $("#name").val();
			 userobj.age = $("#age").val();
			 userobj.address = $("#address").val();
			 userobj.number = $("#number").val();
			 var jso=JSON.stringify(userobj);  
				$.ajax({	   				
	   				type:"post",
	   				url:"updPersonage",
	   				data:{"jso":jso,"uid":user.uid},
	   				dataType:"text",
	   				success:function(data){
			    		if(data=="true"){
			    			$.messager.alert('提示','修改成功','info',function(){
			    				$('#psg').datagrid('reload'); 
			    				$('#dlg').dialog('close')	
				    			}); 			    							 	    					    			
			    		  }else{
			    			  $.messager.alert('提示','修改失败','info',function(){
				    			$('#psg').datagrid('reload'); 
			    			  });
			    		  }
			    	}    		   		
	    		})
			 })
		 })
    }
}

//重置密码
function updPsw(index){
		 $('#psg').datagrid('selectRow',index);
		 var row = $('#psg').datagrid('getSelected');
		 if (row){  
		//获取被选中需要修改的信息	
		 $('#dlg').dialog('open').dialog('center').dialog('setTitle','用户重置密码');
		 $('#fm').form('clear');
		 $('#sd').hide(); $('#refer').show();$('#ok').hide();
		 $('#na').hide(); $('#ag').hide(); 
		 $('#ad').hide(); $('#nm').hide();
		 $('#un').show(); $('#up').show(); 
		 $('#np').show(); $('#nup').show();
		//将获取的需要修改的信息放在修改框里面 
		 var up =$("#psg").datagrid('getSelected');
		 $("#uid").textbox('setValue',up.uid);
		 $("#uname").textbox('setValue',up.uname);
		 $("#upsw").textbox('setValue',up.upsw);
	 }
}
	//将修改的信息请求发送至后台处理 
$(function(){
	$("input",$("#newupsw").next("span")).blur(function(){ 
		var newpsw=$("#newpsw").val();
		var newupsw=$("#newupsw").val();
		if(newpsw!=""&&newupsw!=""){
			if(newpsw!=newupsw){
				$.messager.alert('提示','请确保2次密码一致');
				$("#refer").linkbutton('disable');
			}else{
				$('#refer').linkbutton('enable');
					 $(function(){
						 $("#refer").click(function(){
							 up.uid = $("#uid").val();
							 var upobj=new Object();
							 upobj.uname = $("#uname").val();
							 upobj.upsw = $("#newupsw").val();
							 var jso=JSON.stringify(upobj); 
								$.ajax({	   				
					   				type:"post",
					   				url:"updPassword",
					   				data:{"jso":jso,"uid":up.uid},
					   				dataType:"text",
					   				success:function(data){
							    		if(data=="true"){
							    			$.messager.alert('提示','修改成功','info',function(){
							    		parent.window.location.href='http://localhost:8080/zr_ats/index.jsp'
								    			}); 			    							 	    					    			
							    		  }else{
							    			 $.messager.alert('提示','修改失败','info',function(){
								    		 $('#psg').datagrid('reload'); 
							    			  });
							    	  }
							 	 	}    		   		
					 		   })		
						 })
					 })	
				}
			}else{
				$.messager.alert('提示','密码不能为空');
				$("#refer").linkbutton('disable');
			}
	}) 	
})	

</script>
<body>

	 <table id="psg" title="个人信息查询" class="easyui-datagrid" method="post"
            toolbar="#toolbar" pagination="true" fit="true"  
            striped="true"  checkOnSelect="true"
            rownumbers="true" fitColumns="true" border="false">         
        <thead>
            <tr>              
                <th field="uid" hidden="true">用户编号</th>
                <th field="name" width="50" resizable="false">用户名字</th>
                <th field="age" width="50" resizable="false">用户年龄</th>
                <th field="address" width="50" resizable="false">用户地址</th>
                <th field="number" width="50" resizable="false">用户电话</th>
                <th field="uname" width="50" hidden="true">用户账号</th>
                <th field="upsw" width="50" hidden="true">用户密码</th>
                <th data-options="field:'_operate',width:50,align:'center',formatter:formatOper">操作</th>
            </tr>
        </thead>
    </table> 
    <!--
    <div id="toolbar">       
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="updPer()">修改信息</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="updPsw()">重置密码</a>
    </div>
    -->
      <!-- 个人信息框 -->  
        <div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
            closed="true" buttons="#dlg-buttons">
        <div style="margin-left: 60px"> 
        <div class="ftitle" style="margin-left: 80px">用户信息</div><br>   
        <form id="fm" method="post" novalidate>
             <div class="fitem" id="sd">
                <label>用户编号:</label>
                <input id="uid" class="easyui-textbox" >
            </div>       
            <div class="fitem" id="na">
                <label>用户名字:</label>
                <input id="name" class="easyui-textbox" disabled="true">
            </div>
            <div class="fitem" id="ag">
                <label>用户年龄:</label>
                <input id="age" class="easyui-textbox">
            </div>
            <div class="fitem" id="ad">
                <label>用户地址:</label>
                <input id="address" class="easyui-textbox">
            </div>
            <div class="fitem" id="nm">
                <label>用户电话:</label>
                <input id="number" class="easyui-textbox">
            </div>
            <div class="fitem" id="un">
                <label>用户账号:</label>
                <input id="uname" class="easyui-textbox" disabled="true">
            </div>
            <div class="fitem" id="up">
                <label>用户密码:</label>
                <input id="upsw" class="easyui-textbox" disabled="true">
            </div>
             <div class="fitem" id="np">
                <label>新&nbsp密&nbsp&nbsp码:</label>
                <input id="newpsw" class="easyui-textbox" type="password" 
                required="required" missingMessage="请输入新密码">
            </div>
            <div class="fitem" id="nup">
                <label>再次输入:</label>
                <input id="newupsw" name="newupsw" class="easyui-textbox" 
                type="password" required="required" missingMessage="请再次输入新密码">
            </div>
        </form>
       </div>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok"  style="width:90px;" id="ok" >保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" style="width:90px;" id="refer">重置</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" 
        onclick="javascript:$('#dlg').dialog('close')" style="width:90px;">取消</a>
    </div>
</body>
</html>